package com.asm.DBloader;

import java.util.ArrayList;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;

public class ASM_ServerinfoDS 
{
	private SQLiteDatabase dB;
	private ASM_DB dbHelper;
	Context context;
	
	public ASM_ServerinfoDS(Context context)
	{
		this.context  =context;
		dbHelper = new ASM_DB(context);
	}
	public void open() throws SQLException
	{
		dB = dbHelper.getWritableDatabase();
	}
	
	public int Create(ASM_Serverinfo det) {
		
		int count =0;
		
		if(dB == null){
			open();
		}else if(!dB.isOpen()){
			open();
		}
		
		 
		Cursor cursor = dB.rawQuery("select * from serverinfo ", null);
		
		if(cursor.getCount()>0)
			return -1;	
		
		ContentValues values = new ContentValues();
		values.put(ASM_DB.ASM_SERVERURL, det.getASM_SERVERURL());
		values.put(ASM_DB.ASM_PORT, det.getASM_PORT());
		values.put(ASM_DB.ASM_SERVERDBNAME, det.getASM_SERVERDBNAME());
		values.put(ASM_DB.ASM_ACTIVEPORTS, det.getASM_ACTIVEPORTS());
	
		count = (int) dB.insert(ASM_DB.ASM_SERVER_DETAILS, null, values);

		dB.close();
		return count;
		
	}
	
	
	public String getServerURL() 
	{
		if (dB == null) {
			open();
		} else if (!dB.isOpen()) {
			open();
		}
		
		
	
		String selectQuery = "select "+ASM_DB.ASM_SERVERURL+" from serverinfo";
		Cursor cursor = null;
		cursor = dB.rawQuery(selectQuery, null);
		
		String URL = cursor.getString(0);
		return URL;
	
		
		
	}
}
